<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>事件处理</title>
</head>

<body>
    <div id="app">
        <h2>绑定事件</h2>
        <button @click="test1">test1</button>
        <button @click="test2('atguigu')">test2</button>
        <button @click="test3">test3</button>
        <button @click="test4(123,$event)">test4</button>
        <h2>事件修饰符</h2>
        <div style="height:200px;width: 200px;background: red;" @click="test5">
            <div style="height:100px;width: 100px;background: blue;" @click.stop="test6">停止冒泡</div>
        </div>
        <a href="https://www.baidu.com" @click.prevent="test7">去百度（阻止事件默认行为）</a>
        <h2>按键修饰符</h2>
        <input type="text" @keyup.13="test8">
    </div>
    <script src="https://cdn.bootcss.com/vue/2.5.16/vue.js"></script>
    <script>
        new Vue({
            el: '#app',
            data: {
                test1() {
                    alert('nihh')
                },
                test2(msg) {
                    alert(msg)
                },
                test3(event) {
                    alert(event.target.innerHTML)
                },
                test4(number, event) {
                    alert(number + '-----------' + event.target.innerHTML)
                },
                test5() {
                    alert('out')
                },
                test6() {
                    //event.stopPropagation();原生做法
                    alert('inner')
                },
                test7() {
                    //event.preventDefault()原生做法
                    alert('点击了')
                },
                test8(event) {
                    // if (event.keyCode === 13) {
                    //     alert(event.target.value)
                    // }原生写法
                    alert(event.target.value)
                }
            }
        })
    </script>
</body>

</html>